package network;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.PrintWriter;
import java.net.InetAddress;
import java.net.Socket;
import java.net.UnknownHostException;

public class TCPSender {

	private Socket socketClient = null;
	private InetAddress addressServer = null;
	private int portLocal;
	private int portDistant;
	//private PrintWriter out=null;
	private BufferedReader bufin = null;
	private BufferedWriter bufout = null;
	
	private ObjectOutputStream out;
	private ObjectInputStream in;
	String msg;
	
	public TCPSender(InetAddress addressServer,int portDistant) 
	{
	
		try {
			socketClient=new Socket(addressServer.getHostName(),portDistant);
		} catch (IOException e) {
			System.out.println("Erreur lors de l'ouverture de la socket");
			e.printStackTrace();
		}
	
	}
	
	public void SendTCP(String message)
	{
		try 
		{
			out = new ObjectOutputStream( this.socketClient.getOutputStream() );
			out.writeObject(message);
			out.flush();
			System.out.println("Local>" + msg);
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
}
